package ran.controller.exam;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ran.controller.BaseController;
import ran.domain.exam.dto.ExamAddDTO;
import ran.domain.exam.dto.ExamEditDTO;
import ran.domain.exam.dto.ExamQueryDTO;
import ran.domain.exam.dto.ExamQuestionAddDTO;
import ran.domain.exam.vo.ExamDetailVO;
import ran.domain.exam.vo.ExamVO;
import ran.entity.Result;
import ran.entity.TableDataInfo;
import ran.service.exam.IExamService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-10-23
 * Time: 17:59
 */
@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛API")
public class ExamController extends BaseController {
    @Autowired
    IExamService examService;
    // 所有竞赛列表展示
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        List<ExamVO> list = examService.list(examQueryDTO);
        return toTableDataInfo(list);
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated ExamAddDTO examAddDTO) {
        return Result.ok(examService.add(examAddDTO));
    }
    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId) {
        return toResult(examService.delete(examId));
    }

    @PostMapping("/question/add")
    public Result<Void> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        return toResult(examService.questionAdd(examQuestionAddDTO));
    }
    @DeleteMapping("/question/delete")
    public Result<Void> questionDelete(Long examId, Long questionId) {
        return toResult(examService.questionDelete(examId,questionId));
    }
    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId) {
        return Result.ok(examService.detail(examId));
    }
    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toResult(examService.edit(examEditDTO));
    }
    @PutMapping("/publish")
    public Result<Void> publish(Long examId) {
        return toResult(examService.publish(examId));
    }
    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId) {
        return toResult(examService.cancelPublish(examId));
    }
}
